﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using NUnit.Framework;
using GeometryViz3D.Model;

namespace UnitTests.Model
{
    [TestFixture]
    public class G3DModelTester
    {
        [Test]
        public void TestAddPoint()
        {
            G3DModel model = new G3DModel();

            Assert.IsTrue(model.IsEmpty);
            Assert.IsFalse(model.IsDirty);

            model.AddPoint("A", new Point3D(1.0, 2.0, 3.0));

            Assert.IsFalse(model.IsEmpty);
            Assert.IsTrue(model.IsDirty);

            Assert.AreEqual(new Point3D(1.0, 2.0, 3.0), model.Points[0].Position);

            Assert.AreEqual(3.0, model.Extent);

            model.AddPoint("B", new Point3D(-10.0, -9.0, -8.0));

            Assert.AreEqual(2, model.Points.Count);
            Assert.AreEqual(10.0, model.Extent);
        }

        [Test]
        [ExpectedException(typeof(G3DDuplicateIDException))]
        public void TestAddDuplicatePointIDs()
        {
            G3DModel model = new G3DModel();
            model.AddPoint("A", new Point3D(1.0, 2.0, 3.0));
            model.AddPoint("B", new Point3D(-10.0, -9.0, -8.0));
        }

        [Test]
        public void TestAddLine()
        {
            G3DModel model = new G3DModel();

            Assert.IsTrue(model.IsEmpty);
            Assert.IsFalse(model.IsDirty);

            model.AddPoint("A", new Point3D(1.0, 2.0, 3.0));
            model.AddPoint("B", new Point3D(-10.0, -9.0, -8.0));
            model.AddPoint("C", new Point3D(-1.0, -2.0, -3.0));
            model.AddPoint("D", new Point3D(10.0, 9.0, 8.0));

            model.AddLine("A", "B", "Black");

            Assert.IsFalse(model.IsEmpty);
            Assert.IsTrue(model.IsDirty);

            Assert.AreEqual("AB", model.Lines[0].Label);
            Assert.AreEqual("A", model.Lines[0].StartPoint.Label);
            Assert.AreEqual("B", model.Lines[0].EndPoint.Label);
            Assert.AreEqual(Colors.Black, model.Lines[0].Color);

            model.AddLine("C", "D", "Green");
            Assert.AreEqual(2, model.Lines.Count);
        }

        [Test]
        [ExpectedException(typeof(G3DDuplicateIDException))]
        public void TestAddDuplicateLineIDs()
        {
            G3DModel model = new G3DModel();
            model.AddPoint("A", new Point3D(1.0, 2.0, 3.0));
            model.AddPoint("B", new Point3D(-10.0, -9.0, -8.0));
            model.AddPoint("C", new Point3D(-1.0, -2.0, -3.0));
            model.AddPoint("D", new Point3D(10.0, 9.0, 8.0));

            model.AddLine("A", "B", "Black");
            model.AddLine("C", "D", "Black");
        }

        [Test]
        [ExpectedException(typeof(G3DPointNotExistException))]
        public void TestPointNotExist()
        {
            G3DModel model = new G3DModel();

            model.AddLine("A", "B", "Black");
        }
    }
}
